package com.mapper;

import com.Dto.CounselorInfoDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
@Mapper
public interface CounselorInfoMapper {


    /**咨询师个人信息，包括姓名，平均评分（5分制），总咨询数，总咨询时长
     *
     * @param counselorId
     * @return
     */
    @Select("SELECT c.name AS counselorName, AVG(cs.rating) AS avrRating, COUNT(cs.id) AS totalSessionCount, " +
            "SUM(DATE(cs.time) = CURDATE()) AS todaySessionCount, " +
            "SEC_TO_TIME(SUM(TIME_TO_SEC(cs.session_duration) * (DATE(cs.time) = CURDATE()))) AS todaySessionDuration, " +
            "SEC_TO_TIME(SUM(TIME_TO_SEC(cs.session_duration))) AS totalSessionDuration " +
            "FROM counseling_session cs " +
            "INNER JOIN counselor c ON cs.counselor_id = c.id " +
            "WHERE c.id = #{counselorId} GROUP BY c.id" )
    List<CounselorInfoDto> findCounselorInfo(@Param("counselorId") int counselorId);

}
